﻿using System;
using System.Text;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Skyworth.CRM.Common;
using Skyworth.CRM.Service.IBLL;
using Skyworth.CRM.Service.Entity;
namespace Skyworth.CRM.Web.BasicData
{
    public partial class CustomerDetail : System.Web.UI.Page
    {
        protected int custId = 0;
        private static ICustContactBLL contactBll = IocContainer.Instance.Resolve<ICustContactBLL>();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int.TryParse(Request.QueryString["CustId"], out custId);
                DataTable dtContact = contactBll.Query(string.Format(" FCustId={0}", custId));
                this.custDetailBody.Text = BuildDetail(dtContact);
            }
        }

        protected string BuildDetail(DataTable dtContact)
        {
            StringBuilder result = new StringBuilder();
            if (dtContact != null && dtContact.Rows.Count > 0)
            {
                foreach (DataRow dataRow in dtContact.Rows)
                {
                    result.AppendFormat("<tr><td>{0}</td><td>{1}</td>", dataRow["FName"].ToString(), dataRow["FEmail"].ToString());
                    result.AppendFormat("<td>{0}</td><td>{1}</td>", dataRow["FTel"].ToString(), dataRow["FMobile"].ToString());
                    result.AppendFormat("<td>{0}</td><td>{1}</td>", dataRow["FIsD"].ToString() == "1" ? "true" : "false", dataRow["FDree"].ToString());
                    result.AppendFormat("<td>{0}</td><td>{1}</td>", dataRow["FHobby"].ToString(), dataRow["FNote"].ToString());
                    result.Append("</tr>");
                }
            }
            return result.ToString();
        }
    }
}